var salaryData;
/*初始化*/
function initial(){
	/**
    JSON.stringify()是将JavaScript对象转换为json字符串
  	JSON.parse(jsonstr)是将json字符串转换为javascript对象 
  	*/
	
	//47.94.196.160
	$.ajax({
		url:"http://localhost/PersonManSystem/salary/no/check.action",
//		url:"http://localhost/PersonManSystem/salary/no/check.action",
        type:"get",
        dataType:'json',
        contentType:'application/json;charset=utf-8',
        success:function(data){
          if (data['data'] != null) {
          	salaryData = data;
          	initSalaryLoadData(data);
        	} else {
            alert('所有薪酬标准已经复核完毕');
          }
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){  
          	alert("Error");  
         	alert(XMLHttpRequest.status);  
          	alert(XMLHttpRequest.readyState);  
          	alert(textStatus); 
        }
	});
}

function initSalaryLoadData(data){
	
	var salaryStandardNameSelect = $("#salarystandardname");

	$(data['data']).each(function(){
		salaryStandardNameSelect.append("<option value='" + this.salarystandardname + "'>" + this.salarystandardname + "</option>");
	});
	
	salarystandardnamewhenchange($("#salarystandardname").val());
}

function salarystandardnamewhenchange(salaryStandardName){
	$(salaryData['data']).each(function(){
		if(this.salarystandardname == salaryStandardName) {
        	document.getElementById("salarystandardid").value = this.salarystandardid;
        	document.getElementById("salarystandardname").value = this.salarystandardname;
        	document.getElementById("salarysummoney").value = this.salarysummoney;
        	document.getElementById("settersname").value = this.settersname;
        	document.getElementById("bookername").value = this.bookername;
        	document.getElementById("booktime").value = this.booktime;
        	document.getElementById("basicsalary").value = this.basicsalary;
        	document.getElementById("trafficallowance").value = this.trafficallowance;
        	document.getElementById("lunchallowance").value = this.lunchallowance;
        	document.getElementById("commallowance").value = this.commallowance;
        	document.getElementById("endowmentins").value = this.endowmentins;
        	document.getElementById("uneloymentins").value = this.uneloymentins;
        	document.getElementById("medicalins").value = this.medicalins;
        	document.getElementById("housingfund").value = this.housingfund;
		}
	});

}

function loadBind(){
	//对薪酬标准名称经行级联更新
	$("#salarystandardname").unbind("click");
	$("#salarystandardname").bind("click",function(){
		salarystandardnamewhenchange($("#salarystandardname").val());
	});
	
	/*为提交添加点击事件*/
	$("input[name = 'formsubmit']").unbind("click");
	$("input[name = 'formsubmit']").bind("click", function() {
		submitData();
	});
}

function submitData(){
	var salaryInfo = {
			"salarystandardid" 		:$("input[name='salarystandardid']").val(),
			"salarystandardname" 	:$("input[name='salarystandardname']").val(),
			"salarysummoney" 		:$("input[name='salarysummoney']").val(),	
			"checkername" 			:$("input[name='settersname']").val(),			
			"basicsalary" 			:$("input[name='basicsalary']").val(),
			"trafficallowance" 		:$("input[name='trafficallowance']").val(),
			"lunchallowance" 		:$("input[name='lunchallowance']").val(),
			"commallowance" 		:$("input[name='commallowance']").val(),
			"endowmentins" 			:$("input[name='endowmentins']").val(),
			"medicalins" 			:$("input[name='medicalins']").val(),
			"uneloymentins" 		:$("input[name='uneloymentins']").val(),
			"housingfund" 			:$("input[name='housingfund']").val(),
			"reviewopinion"			:$("input[name='reviewopinion']").val()
	};
	
	 /**
    JSON.stringify()是将JavaScript对象转换为json字符串
  	JSON.parse(jsonstr)是将json字符串转换为javascript对象 
  	*/
	$.ajax({
		url:"http://localhost/PersonManSystem/salary/update/check.action",
//		url:"http://localhost/PersonManSystem/salary/update/check.action",
        type:"PUT",
        dataType:'json',
        contentType:'application/json;charset=utf-8',
        data:JSON.stringify(salaryInfo),
        success:function(data){
        	if (data.msg == '成功') {
        		alert("提交成功！");
        		window.location='XCFH.html';
        	}         
        },
        error:function(XMLHttpRequest, textStatus, errorThrown){  
          	alert("Error");  
         	alert(XMLHttpRequest.status);  
          	alert(XMLHttpRequest.readyState);  
          	alert(textStatus); 
        }
	});
} 